package org.nokatag.code;

import java.awt.Color;
import java.awt.image.BufferedImage;

public class ImageOut {
	
	private String FontColor = "255, 0, 0";//字体颜色
	private Integer Length = 4; //验证码长度
	private Integer Height = 30;//高
	private Integer Width = 300;//宽
	private Integer MaxSize=40;   //字体最大
	private Integer MinSize=20;//字体最小
	private Integer counter=0;//干绕方式
	private String kword=null;
	private String word;
	
	public ImageOut(){
		
	}
	
	public ImageOut(String FontColor){
		this.FontColor = FontColor;
	}
	
	public BufferedImage CreateImage(){
		ConfigurableCaptchaService cs = new ConfigurableCaptchaService();
		//-------------------字的颜色---------------------------------------------
		Integer red = Integer.parseInt(FontColor.split(",")[0].trim());
		Integer blue = Integer.parseInt(FontColor.split(",")[1].trim());
		Integer green = Integer.parseInt(FontColor.split(",")[2].trim());
        cs.setColorFactory(new SingleColorFactory(new Color(red, blue, green)));
        //-------------------验证码长度--------------------------------------------
        RandomWordFactory wf = new RandomWordFactory();
        wf.setMaxLength(Length);
        wf.setMinLength(Length);
        cs.setWordFactory(wf);
        wf.setCharacters(kword);
        //----------------------宽度和高度-----------------------------------------
        cs.setHeight(Height);
        cs.setWidth(Width);
        //-----------------------字体大小---------------------------------------------
        RandomFontFactory rff = new RandomFontFactory();
        rff.setMaxSize(MaxSize);
        rff.setMinSize(MinSize);
        cs.setFontFactory(rff);
        //-----------------------干绕方式--------------------------------------
        switch(counter % 5){
        case 0: // '\0'
            cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory()));
            break;

        case 1: // '\001'
            cs.setFilterFactory(new MarbleRippleFilterFactory());
            break;

        case 2: // '\002'
            cs.setFilterFactory(new DoubleRippleFilterFactory());
            break;

        case 3: // '\003'
            cs.setFilterFactory(new WobbleRippleFilterFactory());
            break;

        case 4: // '\004'
            cs.setFilterFactory(new DiffuseRippleFilterFactory());
            break;
        }
        Captcha cap = cs.getCaptcha();
        
        BufferedImage img = cap.getImage();
        this.word = cap.getWord();
        return img;
	}
	
	
	//=============================================================
	public Integer getCounter() {
		return counter;
	}
	public void setCounter(Integer counter) {
		this.counter = counter;
	}
	public String getFontColor() {
		return FontColor;
	}
	public void setFontColor(String fontColor) {
		FontColor = fontColor;
	}
	public Integer getHeight() {
		return Height;
	}
	public void setHeight(Integer height) {
		Height = height;
	}
	public Integer getLength() {
		return Length;
	}
	public void setLength(Integer length) {
		Length = length;
	}
	public Integer getMaxSize() {
		return MaxSize;
	}
	public void setMaxSize(Integer maxSize) {
		MaxSize = maxSize;
	}
	public Integer getMinSize() {
		return MinSize;
	}
	public void setMinSize(Integer minSize) {
		MinSize = minSize;
	}
	public Integer getWidth() {
		return Width;
	}
	public void setWidth(Integer width) {
		Width = width;
	}

	public String getWord() {
		return word;
	}

	public void setWord(String word) {
		this.word = word;
	}

	public String getKword() {
		return kword;
	}

	public void setKword(String kword) {
		this.kword = kword;
	}
	
	
	
	
	

}
